# where

# In [2]: cond=torch.rand(2,2)

# In [3]: cond
# Out[3]: 
# tensor([[0.9974, 0.5308], 
#         [0.0218, 0.5345]])

# In [4]: a=torch.zeros(2,2)

# In [5]: a
# Out[5]: 
# tensor([[0., 0.],
#         [0., 0.]])

# In [6]: b=torch.ones(2,2)

# In [7]: b
# Out[7]: 
# tensor([[1., 1.],
#         [1., 1.]])

# In [8]: torch.where(cond>0.5,a,b)
# Out[8]: 
# tensor([[0., 0.],
#         [1., 0.]])


# gather

# In [9]: prob=torch.randn(4,10)

# In [10]: idx=prob.topk(dim=1,k=3)

# In [11]: idx
# Out[11]: 
# torch.return_types.topk(
# values=tensor([[ 1.4451,  0.4330,  0.3704],
#         [ 1.4866,  1.2135,  0.2146],
#         [ 1.1228,  0.7691,  0.2644],
#         [ 1.2809,  0.7705, -0.3415]]),
# indices=tensor([[4, 2, 3],
#         [3, 0, 4],
#         [7, 6, 9],
#         [6, 5, 1]]))

# In [12]: idx=idx[1]

# In [13]: idx
# Out[13]: 
# tensor([[4, 2, 3],
#         [3, 0, 4],
#         [7, 6, 9],
#         [6, 5, 1]])

# In [14]: label=torch.arange(10) + 100

# In [15]: label
# Out[15]: tensor([100, 101, 102, 103, 104, 105, 106, 107, 108, 109])

# In [16]: torch.gather(label.expand(4,10),dim=1,index=idx.long())
# Out[16]: 
# tensor([[104, 102, 103],
#         [103, 100, 104],
#         [107, 106, 109],
#         [106, 105, 101]])